<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="单据编码" prop="djbm">
        <el-input
          v-model="queryParams.djbm"
          placeholder="请输入单据编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="调运类型" prop="dylx">
        <el-input
          v-model="queryParams.dylx"
          placeholder="请输入调运类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="起始日期" prop="qsrq">
        <el-date-picker clearable
          v-model="queryParams.qsrq"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择起始日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="终止日期" prop="zzrq">
        <el-date-picker clearable
          v-model="queryParams.zzrq"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择终止日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['sale/contract:fyxszl:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['sale/contract:fyxszl:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['sale/contract:fyxszl:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['sale/contract:fyxszl:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="fyxszlList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="fyXszloid" />
      <el-table-column label="单据编码" align="center" prop="djbm" />
      <el-table-column label="调运类型" align="center" prop="dylx" />
      <el-table-column label="起始日期" align="center" prop="qsrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.qsrq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="终止日期" align="center" prop="zzrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.zzrq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="调运数量" align="center" prop="dysl" />
      <el-table-column label="调运质量" align="center" prop="dyzl" />
      <el-table-column label="单据状态" align="center" prop="djzt" />
      <el-table-column label="备注" align="center" prop="bz" />
      <el-table-column label="C01" align="center" prop="c01" />
      <el-table-column label="责任单位" align="center" prop="zrdw" />
      <el-table-column label="控制方式" align="center" prop="kzfs" />
      <el-table-column label="控制类型" align="center" prop="kzlx" />
      <el-table-column label="控制值" align="center" prop="kzz" />
      <el-table-column label="是否作废" align="center" prop="del" />
      <el-table-column label="执行状态" align="center" prop="zxzt" />
      <el-table-column label="调出单位OID" align="center" prop="dcdwoid" />
      <el-table-column label="承运单位OID" align="center" prop="cydaoid" />
      <el-table-column label="存货档案OID" align="center" prop="jcInventoryoid" />
      <el-table-column label="客商档案OID" align="center" prop="jcKeshangdaoid" />
      <el-table-column label="车辆行走路线OID" align="center" prop="jcIcFlowoid" />
      <el-table-column label="审核人OID" align="center" prop="shroid" />
      <el-table-column label="审核日期" align="center" prop="shrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.shrq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合同编号" align="center" prop="htbh" />
      <el-table-column label="结算价格" align="center" prop="jsjg" />
      <el-table-column label="补充协议编码" align="center" prop="bcxybm" />
      <el-table-column label="运输合同编号" align="center" prop="yshtbm" />
      <el-table-column label="运费含税单价" align="center" prop="yfhsdj" />
      <el-table-column label="运费不含税单价" align="center" prop="yfbhsdj" />
      <el-table-column label="综合途耗" align="center" prop="zhth" />
      <el-table-column label="提货通知单编码" align="center" prop="thtzdbm" />
      <el-table-column label="累计指令量" align="center" prop="ljzll" />
      <el-table-column label="打印责任单位" align="center" prop="dyzrdw" />
      <el-table-column label="结算单位OID" align="center" prop="jsdwoid" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['sale/contract:fyxszl:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['sale/contract:fyxszl:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改销售合同对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="主键" prop="fyXszloid">
          <el-input v-model="form.fyXszloid" placeholder="请输入主键" />
        </el-form-item>
        <el-form-item label="单据编码" prop="djbm">
          <el-input v-model="form.djbm" placeholder="请输入单据编码" />
        </el-form-item>
        <el-form-item label="调运类型" prop="dylx">
          <el-input v-model="form.dylx" placeholder="请输入调运类型" />
        </el-form-item>
        <el-form-item label="起始日期" prop="qsrq">
          <el-date-picker clearable
            v-model="form.qsrq"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择起始日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="终止日期" prop="zzrq">
          <el-date-picker clearable
            v-model="form.zzrq"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择终止日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="调运数量" prop="dysl">
          <el-input v-model="form.dysl" placeholder="请输入调运数量" />
        </el-form-item>
        <el-form-item label="调运质量" prop="dyzl">
          <el-input v-model="form.dyzl" placeholder="请输入调运质量" />
        </el-form-item>
        <el-form-item label="单据状态" prop="djzt">
          <el-input v-model="form.djzt" placeholder="请输入单据状态" />
        </el-form-item>
        <el-form-item label="备注" prop="bz">
          <el-input v-model="form.bz" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="C01" prop="c01">
          <el-input v-model="form.c01" placeholder="请输入C01" />
        </el-form-item>
        <el-form-item label="责任单位" prop="zrdw">
          <el-input v-model="form.zrdw" placeholder="请输入责任单位" />
        </el-form-item>
        <el-form-item label="控制方式" prop="kzfs">
          <el-input v-model="form.kzfs" placeholder="请输入控制方式" />
        </el-form-item>
        <el-form-item label="控制类型" prop="kzlx">
          <el-input v-model="form.kzlx" placeholder="请输入控制类型" />
        </el-form-item>
        <el-form-item label="控制值" prop="kzz">
          <el-input v-model="form.kzz" placeholder="请输入控制值" />
        </el-form-item>
        <el-form-item label="是否作废" prop="del">
          <el-input v-model="form.del" placeholder="请输入是否作废" />
        </el-form-item>
        <el-form-item label="执行状态" prop="zxzt">
          <el-input v-model="form.zxzt" placeholder="请输入执行状态" />
        </el-form-item>
        <el-form-item label="调出单位OID" prop="dcdwoid">
          <el-input v-model="form.dcdwoid" placeholder="请输入调出单位OID" />
        </el-form-item>
        <el-form-item label="承运单位OID" prop="cydaoid">
          <el-input v-model="form.cydaoid" placeholder="请输入承运单位OID" />
        </el-form-item>
        <el-form-item label="存货档案OID" prop="jcInventoryoid">
          <el-input v-model="form.jcInventoryoid" placeholder="请输入存货档案OID" />
        </el-form-item>
        <el-form-item label="客商档案OID" prop="jcKeshangdaoid">
          <el-input v-model="form.jcKeshangdaoid" placeholder="请输入客商档案OID" />
        </el-form-item>
        <el-form-item label="车辆行走路线OID" prop="jcIcFlowoid">
          <el-input v-model="form.jcIcFlowoid" placeholder="请输入车辆行走路线OID" />
        </el-form-item>
        <el-form-item label="审核人OID" prop="shroid">
          <el-input v-model="form.shroid" placeholder="请输入审核人OID" />
        </el-form-item>
        <el-form-item label="审核日期" prop="shrq">
          <el-date-picker clearable
            v-model="form.shrq"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择审核日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合同编号" prop="htbh">
          <el-input v-model="form.htbh" placeholder="请输入合同编号" />
        </el-form-item>
        <el-form-item label="结算价格" prop="jsjg">
          <el-input v-model="form.jsjg" placeholder="请输入结算价格" />
        </el-form-item>
        <el-form-item label="补充协议编码" prop="bcxybm">
          <el-input v-model="form.bcxybm" placeholder="请输入补充协议编码" />
        </el-form-item>
        <el-form-item label="运输合同编号" prop="yshtbm">
          <el-input v-model="form.yshtbm" placeholder="请输入运输合同编号" />
        </el-form-item>
        <el-form-item label="运费含税单价" prop="yfhsdj">
          <el-input v-model="form.yfhsdj" placeholder="请输入运费含税单价" />
        </el-form-item>
        <el-form-item label="运费不含税单价" prop="yfbhsdj">
          <el-input v-model="form.yfbhsdj" placeholder="请输入运费不含税单价" />
        </el-form-item>
        <el-form-item label="综合途耗" prop="zhth">
          <el-input v-model="form.zhth" placeholder="请输入综合途耗" />
        </el-form-item>
        <el-form-item label="提货通知单编码" prop="thtzdbm">
          <el-input v-model="form.thtzdbm" placeholder="请输入提货通知单编码" />
        </el-form-item>
        <el-form-item label="累计指令量" prop="ljzll">
          <el-input v-model="form.ljzll" placeholder="请输入累计指令量" />
        </el-form-item>
        <el-form-item label="打印责任单位" prop="dyzrdw">
          <el-input v-model="form.dyzrdw" placeholder="请输入打印责任单位" />
        </el-form-item>
        <el-form-item label="结算单位OID" prop="jsdwoid">
          <el-input v-model="form.jsdwoid" placeholder="请输入结算单位OID" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFyxszl, getFyxszl, delFyxszl, addFyxszl, updateFyxszl } from "@/api/sale/contract/fyxszl";

export default {
  name: "Fyxszl",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 销售合同表格数据
      fyxszlList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        djbm: null,
        dylx: null,
        qsrq: null,
        zzrq: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        fyXszloid: [
          { required: true, message: "主键不能为空", trigger: "blur" }
        ],
        djbm: [
          { required: true, message: "单据编码不能为空", trigger: "blur" }
        ],
        dylx: [
          { required: true, message: "调运类型不能为空", trigger: "blur" }
        ],
        qsrq: [
          { required: true, message: "起始日期不能为空", trigger: "blur" }
        ],
        zzrq: [
          { required: true, message: "终止日期不能为空", trigger: "blur" }
        ],
        dysl: [
          { required: true, message: "调运数量不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询销售合同列表 */
    getList() {
      this.loading = true;
      listFyxszl(this.queryParams).then(response => {
        this.fyxszlList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        fyXszloid: null,
        djbm: null,
        dylx: null,
        qsrq: null,
        zzrq: null,
        dysl: null,
        dyzl: null,
        djzt: null,
        bz: null,
        c01: null,
        zrdw: null,
        kzfs: null,
        kzlx: null,
        kzz: null,
        del: null,
        zxzt: null,
        dcdwoid: null,
        cydaoid: null,
        jcInventoryoid: null,
        jcKeshangdaoid: null,
        jcIcFlowoid: null,
        shroid: null,
        shrq: null,
        htbh: null,
        jsjg: null,
        bcxybm: null,
        yshtbm: null,
        yfhsdj: null,
        yfbhsdj: null,
        zhth: null,
        thtzdbm: null,
        ljzll: null,
        dyzrdw: null,
        jsdwoid: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.fyXszloid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加销售合同";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const fyXszloid = row.fyXszloid || this.ids
      getFyxszl(fyXszloid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改销售合同";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.fyXszloid != null) {
            updateFyxszl(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFyxszl(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const fyXszloids = row.fyXszloid || this.ids;
      this.$modal.confirm('是否确认删除销售合同编号为"' + fyXszloids + '"的数据项？').then(function() {
        return delFyxszl(fyXszloids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('sale/contract/fyxszl/export', {
        ...this.queryParams
      }, `fyxszl_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
